﻿using AutoMapper;
using EquipmentModule.Entity;
using EquipmentModule.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace EquipmentModule.Profiles
{
    public class AutoMapperProfile: Profile
    {
        public AutoMapperProfile()
        {
            CreateMap<EquipmentViewModel4Add, Equipment>()
                .ForMember(x => x.X, opt => opt.MapFrom(k => k.Position[0]))
                .ForMember(x => x.Y, opt => opt.MapFrom(k => k.Position[1]));

            CreateMap<EquipmentViewModel4Edit, Equipment>()
                .ForMember(x => x.X, opt => opt.MapFrom(k => k.Position[0]))
                .ForMember(x => x.Y, opt => opt.MapFrom(k => k.Position[1]));

            CreateMap<Section, SectionViewModel>()
                .ForMember(x=>x.Position,opt=>opt.MapFrom(k=>new double?[] { k.X,k.Y}));

            CreateMap<Section, SectionViewModel4Item>()
                .ForMember(x => x.SectionPosition, opt => opt.MapFrom(k => new double?[] { k.X, k.Y }))
                .ForMember(x => x.SectionName, opt => opt.MapFrom(k => k.Name));

            CreateMap<EquipmentHistoryItem, EquipmentHistoryItemViewModel>()
                 .ForMember(x => x.Name, opt => opt.MapFrom(k => k.TagName))
                 .ForMember(x => x.CreateTime, opt => opt.MapFrom(k => k.CreateTime))
                 .ForMember(x => x.Value, opt => opt.MapFrom(k => k.Value));
        }
    }
}
